package com.playfab
{
    public class PlayFabError
    {
        public static const Unknown:int = 1;
        public static const NetworkIOError:int = 2;
        public static const FlashSecurityError:int = 3;

<% for(var eachErrIdx in apis[0].errors) { var errorProps = apis[0].errors[eachErrIdx]
%>        public static const <%- errorProps.name %>:int = <%- errorProps.id %>;
<% } %>

        public function PlayFabError(data:Object=null)
        {
            if(data == null) return;
            httpCode = data.code;
            httpStatus = data.status;
            error = data.error;
            errorCode = data.errorCode;
            errorMessage = data.errorMessage;
            errorDetails = data.errorDetails;
        }

        public var httpCode:int; // HTTP return code
        public var httpStatus:String; // HTTP status
        public var error:String; // PlayFab error enum-string
        public var errorCode:int; // PlayFab error code
        public var errorMessage:String; // PlayFab specific error message
        public var errorDetails:Object; // Additional error details: frequently null, but if errorMessage is vague, this may contain more information

        public function GenerateErrorReport() : String
        {
            var message:String = errorMessage;
            for (var key:String in errorDetails) {
                message += "\n";
                message += key + ": " + errorDetails[key];
            }
            return message;
        }
    }
}
